package kara;



import java.io.*;
//代码随想录p100dfs实现
public class A100P2 {
    static int n;
    static int m;
    static int[][] map;
    static int res=0;
    static int[] dir1={1,0,-1,0};
    static int[] dir2={0,1,0,-1};
    static int ans;
    static BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter log=new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException {
        String[] split = read.readLine().split(" ");
        n=Integer.parseInt(split[0]);
        m=Integer.parseInt(split[1]);
        map=new int[n][m];
        for(int i=0;i<n;i++){
            String[] s = read.readLine().split(" ");
            for(int j=0;j<m;j++){
                map[i][j]=Integer.parseInt(s[j]);
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(map[i][j]==1){
                    //写法一，dfs处理当前节点的相邻节点，即在主函数遇到岛屿就计数为1，dfs处理接下来的相邻陆地
                    map[i][j]=0;
                     ans=1;
                   dfs(i,j);
                    res=res>=ans?res:ans;
                }
            }
        }
        log.write(Integer.toString(res));
        log.flush();
    }

    static void dfs(int x,int y){
        for(int i=0;i<4;i++) {
            int a = x + dir1[i];
            int b = y + dir2[i];
            if (a >= 0 && a < n && b >= 0 && b < m && map[a][b] == 1) {
//标记为海洋
                map[a][b] = 0;
                ans++;
                dfs(a,b);
            }
        }
    }
}
